package com.example.talkheart.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.talkheart.entity.ScoreBean
import com.example.talkheart.entity.TeacherBean

@Database(entities=[ScoreBean::class,TeacherBean::class], version = 1, exportSchema = false)
abstract class ScoreDatabase : RoomDatabase(){
    abstract val scoreDatabaseDao : ScoreDatabaseDao
    abstract val teacherDatabaseDao : TeacherDatabaseDao
    companion object{
        @Volatile
        private var INSTANCE : ScoreDatabase?=null

        fun getScoreInstance(context: Context) : ScoreDatabase{
            var instance = INSTANCE
            if (instance == null){
                instance = Room.databaseBuilder(
                    context.applicationContext,
                    ScoreDatabase::class.java,
                    "score_database"
                ).fallbackToDestructiveMigration()
                    .build()
                INSTANCE = instance
            }
            return instance
        }
    }
}